package SlidingWindow;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-10-13
 * Time: 10:22
 *
 */
class Solution3 {
    public int longestOnes(int[] nums, int k) {
        int left = 0 , right = 0 , count = 0;
        int n = nums.length , ret = 0;
        while(right < n){
            if(nums[right] == 1){
                right++;
            }else{
                count++;
                right++;
            }
            while(count > k){
                if(nums[left] == 1){
                    left++;
                }else{
                    count--;
                    left++;
                }

            }


            ret = Math.max(ret,right-left);

        }
        return ret;

    }
}
public class Test3 {
}
